﻿using System;
using System.Collections.Generic;

namespace DigitalQuran.Collection {
    
    /// <summary>
    /// Collection of <see cref="DigitalQuran.Letter"/>
    /// </summary>
    public class LetterCollection : ReadOnlyCollection<Letter> {
        List<Letter> _Letters;

        /// <summary>
        /// Create new instance
        /// </summary>
        /// <param name="wordIndex">Index of Word in Qur'an</param>
        public LetterCollection(int wordIndex)
            : base(0) {

            var w = WordCollection.GetWord(wordIndex);
            var text = w.ToString(Book.OrignalTextMode);
            _Letters = new List<Letter>(text.Length);
            foreach (char character in text) {
                if (character == ' ' ||
                    character == '\r' ||
                    character == '\n' ||
                    Constants.StopMarkers.Contains(character)) continue;

                _Letters.Add(new Letter(w, character));
            }

            base.Count = _Letters.Count;
        }

        public override Letter this[int index] {
            get {
                return _Letters[index];
            }
        }

        public override IEnumerator<Letter> GetEnumerator() {
            return _Letters.GetEnumerator();
        }
    }
}